﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class SocketServerModule : MonoBehaviour {
    public SocketServer _Server{get; private set;}

    public NetMsgCenter _msgCenter { get; private set; }
    public void Init()
    {
        _Server = new SocketServer();
        _Server.StartListen(SocketTool.GetIpAddress(),"2999");
        _msgCenter = new GameObject("msgCenter", typeof(NetMsgCenter)).GetComponent<NetMsgCenter>();
        _msgCenter.transform.SetParent(this.transform);
        _Server.ReceiveCallBack += (x) => { _msgCenter._netRcvMsg.Enqueue(x); };
    }
    void Start ()
    {
        Init();
        //SocketTool.TransByte2Msg(SocketTool.TransMsg2Byte("StrMsg", "rfdsf34")) ;

    }

    private void OnDestroy()
    {
        _Server.StopListen_Click();
    }

    public void SendTest()
    {
        _Server.Send("serverType", "helloCLient");
    }
}
